﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Onshi.POS.AccesoDatos.Interfaces;
using System.Data;
using System.Data.SqlClient;

namespace Onshi.POS.AccesoDatos
{
    public class ServicioDatosRegistros : ServicioDatosBase, IServicioDatosRegistros
    {
        #region Metodos

        public DataSet Registros_DevolverPorId(Int32 idRegistro)
        {
            try
            {
                var cm = new SqlCommand("Registros_DevolverPorId", Conexion);
                cm.CommandType = CommandType.StoredProcedure;
                cm.Parameters.AddWithValue("@IdRegistro", idRegistro);
                var da = new SqlDataAdapter(cm);
                var ds = new DataSet();
                da.Fill(ds);
                return ds;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                if (Conexion.State == ConnectionState.Open)
                    Conexion.Close();
            }
        }

        public Int32 Registros_Insertar(Byte idEvento, Int32 idUsuario)
        {
            try
            {
                var cm = new SqlCommand("Registros_Insertar", Conexion);
                cm.CommandType = CommandType.StoredProcedure;
                cm.Parameters.AddWithValue("@IdEvento", idEvento);
                cm.Parameters.AddWithValue("@IdUsuario", idUsuario);
                cm.Connection.Open();
                return Convert.ToInt32(cm.ExecuteScalar());
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                if (Conexion.State == ConnectionState.Open)
                    Conexion.Close();
            }
        }

        public void RegistrosVendedores_Insertar(Int32 idRegistro, Int32 idVendedor)
        {
            try
            {
                var cm = new SqlCommand("RegistrosVendedores_Insertar", Conexion);
                cm.CommandType = CommandType.StoredProcedure;
                cm.Parameters.AddWithValue("@IdRegistro", idRegistro);
                cm.Parameters.AddWithValue("@IdVendedor", idVendedor);
                cm.Connection.Open();
                cm.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                if (Conexion.State == ConnectionState.Open)
                    Conexion.Close();
            }
        }

        public void RegistrosUsuarios_Insertar(Int32 idRegistro, Int32 idUsuario)
        {
            try
            {
                var cm = new SqlCommand("RegistrosUsuarios_Insertar", Conexion);
                cm.CommandType = CommandType.StoredProcedure;
                cm.Parameters.AddWithValue("@IdRegistro", idRegistro);
                cm.Parameters.AddWithValue("@IdUsuario", idUsuario);
                cm.Connection.Open();
                cm.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                if (Conexion.State == ConnectionState.Open)
                    Conexion.Close();
            }
        }

        public void RegistrosClientes_Insertar(Int32 idRegistro, Int32 idCliente)
        {
            try
            {
                var cm = new SqlCommand("RegistrosClientes_Insertar", Conexion);
                cm.CommandType = CommandType.StoredProcedure;
                cm.Parameters.AddWithValue("@IdRegistro", idRegistro);
                cm.Parameters.AddWithValue("@IdCliente", idCliente);
                cm.Connection.Open();
                cm.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                if (Conexion.State == ConnectionState.Open)
                    Conexion.Close();
            }
        }

        public void RegistrosProveedores_Insertar(Int32 idRegistro, Int32 idProveedor)
        {
            try
            {
                var cm = new SqlCommand("RegistrosProveedores_Insertar", Conexion);
                cm.CommandType = CommandType.StoredProcedure;
                cm.Parameters.AddWithValue("@IdRegistro", idRegistro);
                cm.Parameters.AddWithValue("@IdProveedor", idProveedor);
                cm.Connection.Open();
                cm.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                if (Conexion.State == ConnectionState.Open)
                    Conexion.Close();
            }
        }

        public void RegistrosArticulos_Insertar(Int32 idRegistro, Int32 idArticulo)
        {
            try
            {
                var cm = new SqlCommand("RegistrosArticulos_Insertar", Conexion);
                cm.CommandType = CommandType.StoredProcedure;
                cm.Parameters.AddWithValue("@IdRegistro", idRegistro);
                cm.Parameters.AddWithValue("@IdArticulo", idArticulo);
                cm.Connection.Open();
                cm.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                if (Conexion.State == ConnectionState.Open)
                    Conexion.Close();
            }
        }

        public void RegistrosOrdenesCompras_Insertar(Int32 idRegistro, Int32 idOrdenCompra)
        {
            try
            {
                var cm = new SqlCommand("RegistrosOrdenesCompras_Insertar", Conexion);
                cm.CommandType = CommandType.StoredProcedure;
                cm.Parameters.AddWithValue("@IdRegistro", idRegistro);
                cm.Parameters.AddWithValue("@IdOrdenCompra", idOrdenCompra);
                cm.Connection.Open();
                cm.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                if (Conexion.State == ConnectionState.Open)
                    Conexion.Close();
            }
        }

        public void RegistrosImpuestos_Insertar(Int32 idRegistro, Int32 idImpuesto)
        {
            try
            {
                var cm = new SqlCommand("RegistrosImpuestos_Insertar", Conexion);
                cm.CommandType = CommandType.StoredProcedure;
                cm.Parameters.AddWithValue("@IdRegistro", idRegistro);
                cm.Parameters.AddWithValue("@IdImpuesto", idImpuesto);
                cm.Connection.Open();
                cm.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                if (Conexion.State == ConnectionState.Open)
                    Conexion.Close();
            }
        }
    
        #endregion
    }
}
